<template>
  <el-card class="box-card">
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="科室">
        <template slot-scope="scope">
          <el-select @change="findDoctorBySearch" v-model="form.departid" placeholder="请选择">
            <el-option
                    v-for="item in depart"
                    :key="item.departId"
                    :label="item.name"
                    :value="item.departId">
            </el-option>
          </el-select>
        </template>
      </el-form-item>
      <el-form-item label="医生">
        <template  slot-scope="scope">
          <el-select  v-model="form.docid" placeholder="请选择">
            <el-option
                    v-for="item in doctor"
                    :key="item.docId"
                    :label="item.realName"
                    :value="item.docId">
            </el-option>
          </el-select>
        </template>
      </el-form-item>

      <el-form-item label="挂号费">
        <el-input v-model="form.rocharge"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即创建</el-button>
        <el-button @click="cancel">取消</el-button>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script>
  import {add} from '@/network/register'
  import {findAllDept} from '@/network/dept'
  import {findDoctorBySearch} from '@/network/doctor'

  export default {
    name: 'registerOrderAdd',
    created() {
      this.findAllDept()
      this.findDoctorBySearch()
    },
    methods: {
      onSubmit() {
        console.log(this.form)
        add(this.form).then(res => {
          this.$router.back(1)
        })
      },
      cancel() {
        this.$router.back(1)
      },
      findAllDept() {
        findAllDept().then(res => {
          console.log(res.data.data.records)
          this.depart = res.data.data.records
        })
      }  ,
      findDoctorBySearch() {
        findDoctorBySearch(this.form.departid).then(res => {
          console.log(res)
          this.doctor = res.data.data
        })
      }
    },
    data() {
      return {
        form: {
          memberid: window.sessionStorage.getItem("memberid")
        },
        depart: [],
        doctor: [],

      }
    }
  }
</script>

<style scoped>

</style>
